//
//  OrganizationalLifeTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/8/5.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "OrganizationalLifeTableViewCell.h"

@interface OrganizationalLifeTableViewCell ()
//标题
@property (nonatomic , strong) UILabel * cellTitleLabel;
//活动地点
@property (nonatomic , strong) UILabel * addressLabel;
//开始时间
@property (nonatomic , strong) UILabel * beginTimeLabel;

//当前状态
@property (nonatomic , strong) UILabel * statusLabel;
@end

@implementation OrganizationalLifeTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initMyCell];
    }
    return self;
}


-(void)initMyCell{
    TenGrayShadowView *under = [[TenGrayShadowView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 10 * [UIScreen zj_screenHScale])];
    under.backgroundColor = [UIColor themeGrayColor];
    under.isRemoveTop = YES;
    [self.contentView addSubview:under];
    //logo
    UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ItemWidth * 24, ItemHeight * 45, ItemHeight * 39, ItemHeight * 39)];
    logoImageView.image = [UIImage imageNamed:@"mine_con_zzsh"];
    [self.contentView addSubview:logoImageView];
    
    [self.contentView addSubview:self.cellTitleLabel];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.beginTimeLabel];
    [self.contentView addSubview:self.optionButton];
    [self.contentView addSubview:self.statusLabel];
    self.addressLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.cellTitleLabel , ItemHeight * 26).widthIs(ItemWidth * 500).heightIs(ItemHeight * 39);
    
    self.beginTimeLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.addressLabel , 0).widthIs(ItemWidth * 500).heightIs(ItemHeight * 39);
    
    self.statusLabel.sd_layout.rightSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , ItemHeight * 90).widthIs(ItemWidth * 124).heightIs(ItemHeight * 39);
    
    
    self.optionButton.sd_layout.leftSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , -1).widthIs([UIScreen zj_screenWith]).heightIs(ItemHeight * 60);
}

-(void)setModel:(BranchNormalModel *)model
{
    _model = model;
    BranchActivityModel * tempModel = (BranchActivityModel *)model;
    self.cellTitleLabel.frame = CGRectMake(ItemWidth * 74, self.titleBeginY + 20 * ItemHeight, ItemWidth * 642, model.titleHeight);
    self.cellTitleLabel.attributedText = tempModel.titleAttributedString;
    self.addressLabel.attributedText = tempModel.addressAttributedString;
    NSString * timeString = tempModel.START_TIME;
    timeString = [timeString componentsSeparatedByString:@"."][0];
    if (timeString.length > 0) {
        timeString = [NSDateFormatter formatterDateStringWithDateString:timeString];
    }
    self.beginTimeLabel.text = [NSString stringWithFormat:@"开始时间：%@" , timeString];
    if ([tempModel.STATUS integerValue] == 0) {
        self.statusLabel.text = @"预报名";
    }
    else{
        if ([tempModel.LEAVE_STATUS integerValue] == -1) {
            self.statusLabel.text = @"已报名";
        }
        else if([tempModel.LEAVE_STATUS integerValue] == 2){
            self.statusLabel.text = @"拒绝";
        }
        else if([tempModel.LEAVE_STATUS integerValue] == 1){
            self.statusLabel.text = @"已请假";
        }
        else{
            self.statusLabel.text = @"待审核";
        }
    }
    
    if ([tempModel.STATUS integerValue] == 0) {
        self.optionButton.hidden = NO;
        [self.optionButton setTitle:@"报名" forState:UIControlStateNormal];
    }
    else{
        [self.optionButton setTitle:@"请假" forState:UIControlStateNormal];
        if ([tempModel.LEAVE_STATUS integerValue] == -1) {
            self.optionButton.hidden = NO;
            self.statusLabel.sd_layout.rightSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , ItemHeight * 90).widthIs(ItemWidth * 124).heightIs(ItemHeight * 39);
            [self.statusLabel updateLayout];
        }
        else{
            self.optionButton.hidden = YES;
            self.statusLabel.sd_layout.rightSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , ItemHeight * 30).widthIs(ItemWidth * 124).heightIs(ItemHeight * 39);
            [self.statusLabel updateLayout];
        }
    }
    self.addressLabel.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 74).topSpaceToView(self.cellTitleLabel , ItemHeight * 26).widthIs(ItemWidth * 500).heightIs(tempModel.addressHeight);
    [self.addressLabel updateLayout];
}





//标题
-(UILabel *)cellTitleLabel
{
    if (!_cellTitleLabel) {
        _cellTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 25, ItemWidth * 642, ItemHeight * 39) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _cellTitleLabel;
}
//活动地点
-(UILabel *)addressLabel
{
    if (!_addressLabel) {
        _addressLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 90, ItemWidth * 500 , ItemHeight * 39) font:14 textColor:[UIColor textBlackColor] text:@""];
    }
    return _addressLabel;
}
//开始时间
-(UILabel *)beginTimeLabel
{
    if (!_beginTimeLabel) {
        _beginTimeLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, ItemHeight * 119, ItemWidth * 500, ItemHeight * 39) font:14 textColor:[UIColor textBlackColor] text:@""];
    }
    return _beginTimeLabel;
}
//下方按钮
-(UIButton *)optionButton
{
    if (!_optionButton) {
        _optionButton = [ToolClass createButtonWithFrame:CGRectMake(0, ItemHeight * 188, [UIScreen zj_screenWith], ItemHeight * 60) text:@"请假" textColor:[UIColor themeColor] imageName:@"" font:16];
        _optionButton.backgroundColor = [UIColor zj_colorWithHexString:@"e8f2fa"];
//        _optionButton.layer.shadowOffset = CGSizeMake(0, 2);
//        _optionButton.layer.shadowColor = [UIColor blackColor].CGColor;
//        _optionButton.layer.shadowOpacity = 0.2;
    }
    return _optionButton;
}
//当前状态
-(UILabel *)statusLabel
{
    if (!_statusLabel) {
        _statusLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 626, ItemHeight * 119, ItemWidth * 124, ItemHeight * 39) font:14 textColor:[UIColor themeColor] text:@""];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _statusLabel;
}












@end
